//
//  ByDocumentaryHeadView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/27.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryHeadView.h"

@implementation ByDocumentaryHeadView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        NSArray *titlesAry = @[@"红人榜",@"命中榜",@"盈利榜"];
        NSArray *imagesAry = @[@"hongrenbang红人榜",@"mingzhongabng命中棒",@"yinglibang"];
        CGFloat width = SCREEN_WIDTH / 3.0;
        for (int i = 0; i< 3; i++) {
            UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake(width * i, 0, width, frame.size.height - 3)];
            [self addSubview:control];
            [control addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
            
            UIImageView *iconView = [[UIImageView alloc] init];
            [control addSubview:iconView];
            [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(control).offset(10);
                make.centerX.equalTo(control).offset(0);
                make.size.mas_equalTo(CGSizeMake(50, 50));
            }];
            iconView.image = [UIImage imageNamed:imagesAry[i]];
            
            
            
            UILabel *titleLabel = [[UILabel alloc] init];
            [control addSubview:titleLabel];
            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(iconView.mas_bottom).offset(5);
                make.height.mas_equalTo(@20);
                make.right.equalTo(control).offset(0);
                make.left.equalTo(control).offset(0);
            }];
            
            titleLabel.font = FONT(14);
            titleLabel.textColor = [UIColor blackColor];
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.text = titlesAry[i];
            control.tag = 100 + i;
            [control addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
            
        }
        
        
        UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 3, SCREEN_WIDTH, 3)];
        line.backgroundColor = BY_LINE_COLOR;
        [self addSubview:line];
    }
    return self;
}

- (void)controlAction:(UIControl *)control{
    if (self.selectBlock) {
        self.selectBlock(control.tag - 100);
    }
    
}


@end
